package com.example.markingsystem.controller;

import com.example.markingsystem.bean.externalteacher;
import com.example.markingsystem.bean.openidrecord;
import com.example.markingsystem.mapper.ExternalteacherMapper;
import com.example.markingsystem.mapper.LoginMapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ExternalteacherController {
    @Resource
    private ExternalteacherMapper externalteacherMapper;

    @Resource
    private LoginMapper loginMapper;

    @RequestMapping("addExternalteacherInfo")
    public String addExternalteacherInfo(@Param("name") String name,
                                         @Param("idcard") String idcard,
                                         @Param("telephone") String telephone,
                                         @Param("region") String region,
                                         @Param("professionaltitle") String professionaltitle,
                                         @Param("duties") String duties,
                                         @Param("unitname") String unitname,
                                         @Param("unitphone") String unitphone,
                                         @Param("bankcardnumber") String bankcardnumber,
                                         @Param("openbankadd") String openbankadd,
                                         @Param("openbank") String openbank,
                                         @Param("vehiclesinter")int vehiclesinter,
                                         @Param("accommodation")int accommodation,
                                         HttpSession session){
        externalteacher e = new externalteacher();
        String nowuseridcode = (String) session.getAttribute("userlogin");
        e.setIdcode(nowuseridcode);

        e.setName(name);
        e.setIdcard(idcard);
        e.setTelephone(region+telephone);
        e.setProfessionaltitle(professionaltitle);
        e.setDuties(duties);
        e.setUnitname(unitname);
        e.setUnitphone(unitphone);
        e.setBankcardnumber(bankcardnumber);
        e.setOpenbankadd(openbankadd);
        e.setOpenbank(openbank);
        e.setVehiclesinter(vehiclesinter);
        e.setAccommodation(accommodation);

        externalteacherMapper.addInfo(e);


        String nowopenid = (String) session.getAttribute("nowopenid");
        openidrecord nowrecord = new openidrecord();
        nowrecord.setIdcode(nowuseridcode);
        nowrecord.setOpenid(nowopenid);
        loginMapper.insertOpenidRecord(nowrecord);
        return "test";
    }

    @RequestMapping("toAddExternalteacherInfo")
    public String toAddGraduateInfo(){
        return "waixiaolaoshiInfo";
    }
}
